<?php

    session_start();
    
    // include the controller for the requested page
    $uri = explode('?', $_SERVER['REQUEST_URI']);
    $url = explode('/', $uri[0]);

    $page = isset($url[1]) && !empty($url[1]) ? $url[1] : 'select';

    $filename = ucfirst(strtolower($page));
    $path = '../controller/' . $filename;
    
    if (file_exists($path . '.php')) {
        require_once $path . '.php';
        $controller_name = 'Controller_' . $filename;
        $controller = new $controller_name();
        $controller->index();
    } else {
        // if the requsted page was not found (no controller)
        // include the error page
        require_once '../controller/Error.php';
        $controller = new Controller_Error();
        $controller->index();
    }